// 登录信息
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user-login', {
    state: () => ({
        token: "",
        userInfo: {
            userName: "海之蓝",
            nickName: "小章鱼",
            avatar: "/images/avatar.png",
            email: '123@qq.com',
            phone: '187267489',
            age: '18',
            gender: 'm',
            identify: '1',
            menuList: [
                {
                    icon: 'PieChartOutlined',
                    index: "/home/dashboard",
                    title: "仪表盘",
                },
                {
                    icon: 'BookOutlined',
                    index: "/home/word",
                    title: "富文本编辑器",
                },
                {
                    icon: 'ToolOutlined',
                    index: "",
                    title: "系统管理",
                    subItem: [
                        {
                            icon: 'MehOutlined',
                            index: "/home/role",
                            title: "角色管理",
                        },
                        {
                            icon: 'UnlockOutlined',
                            index: "/home/permission",
                            title: "权限管理",
                        },
                        {
                            icon: 'UserOutlined',
                            index: "/home/user",
                            title: "用户管理",
                        }
                    ]
                }
            ]

        }
    }),
    actions: {
        setToken(token) {
            this.token = token;
        },

        setInfo(userInfo) {
            this.userInfo = userInfo;
        },
        clearAll() {
            this.token = '';
            this.userInfo = null;
        }
    },
    persist: {
        enabled: true, // 开启持久化
        strategies: [
            {
                key: 'user-login', // 存储的key
                storage: localStorage, // 存储方式
                paths: ['token', 'userInfo'] // 指定要持久化的state
            }
        ]
    }
})
